<?php
/************************
 *  Codenova.pl Project
 *  Created by: Kamil Mrzygłód
 *
 *  (c) 2013 by Codenova.pl 
 *  All Right Reserved
 ***********************/

namespace Gotcha;

use Gotcha\App\GotchaBootstrap;
use Gotcha\App\GotchaEngine;

error_reporting(E_ALL);

// System version
define('GOTCHA_SYSTEM_VERSION', '1.0-a20');

// Define absolute path
$path_info = pathinfo($_SERVER['PHP_SELF']); // Get current path info
$base_path = explode('/', $path_info['dirname']); // Split path to remove blank first name and filename

// We have to delete third key since it's 'index.php'
if (count($base_path) >= 1) {
    $i = 0;
    foreach($base_path as $path_to_remove) {
        if ($i >= 2) {
            unset($base_path[$i]);
        }
        $i++;
    }

    // Restore indexes
    array_values($base_path);
}

// Remove blank first item
array_shift($base_path);

// Our application base path
define('GOTCHA_BASE_PATH', '/'.implode('/', $base_path));
define('GOTCHA_ROOT_DIR', dirname(__FILE__));

// Since we have a lot of include paths, we should clean it up a bit
$include_paths = array(GOTCHA_ROOT_DIR.'/App/Extensions/', GOTCHA_ROOT_DIR.'/App/Repositories/', GOTCHA_ROOT_DIR.'/App/Database/classes/gotcha/', GOTCHA_ROOT_DIR.'/App/Database/classes/gotcha/om/', GOTCHA_ROOT_DIR.'/App/Database/classes/gotcha/map/', GOTCHA_ROOT_DIR.'/App/Libs/Propel/runtime/lib/config/', GOTCHA_ROOT_DIR.'/App/Libs/Propel/runtime/lib/util/', GOTCHA_ROOT_DIR.'/App/Libs/Propel/runtime/lib/om/', GOTCHA_ROOT_DIR.'/App/Libs/Propel/runtime/lib/map/', GOTCHA_ROOT_DIR.'/App/Libs/Propel/runtime/lib/exception/', GOTCHA_ROOT_DIR.'/App/Libs/Propel/runtime/lib/connection/', GOTCHA_ROOT_DIR.'/App/Libs/Propel/runtime/lib/adapter/', GOTCHA_ROOT_DIR.'/App/Libs/Propel/runtime/lib/query/', GOTCHA_ROOT_DIR.'/App/Libs/Propel/runtime/lib/parser/', GOTCHA_ROOT_DIR.'/App/Libs/Propel/runtime/lib/parser/yaml/', GOTCHA_ROOT_DIR.'/App/Libs/Propel/runtime/lib/collection/', GOTCHA_ROOT_DIR.'/App/Libs/Propel/runtime/lib/formatter/', GOTCHA_ROOT_DIR.'/App/Types/', GOTCHA_ROOT_DIR.'/Modules/JasminumNews/Controllers/', GOTCHA_ROOT_DIR.'/Modules/JasminumReservations/Controllers/', GOTCHA_ROOT_DIR.'/App/Libs/PHPMailer/', GOTCHA_ROOT_DIR.'/Modules/JasminumGallery/Controllers/');

// Update include path
set_include_path(implode(PATH_SEPARATOR, $include_paths) . PATH_SEPARATOR . get_include_path());

// Include bootstrap and engine
require_once 'App/GotchaBootstrap.php';
require_once 'App/GotchaEngine.php';

$init = new GotchaBootstrap();
$init->init();

$run = new GotchaEngine();
$run->run();
?>